using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class ChiTietChuyenBayDAO
    {
        public static bool ChonHetCTChuyenBay(List<DTO.ChiTietChuyenBay> dschitiet)
        {
            string sql = "Select * from ChiTietMayBay";
            DataTable dt = Config.AccessHelper.ExecuteQuery(sql);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    DTO.ChiTietChuyenBay ct = new DTO.ChiTietChuyenBay();
                    ct.MaChuyenBay = dt.Rows[i].ItemArray[0].ToString();
                    ct.SanBayTrungGian = int.Parse(dt.Rows[i].ItemArray[1].ToString());
                    ct.ThoiGianDung = DateTime.Parse(dt.Rows[i].ItemArray[2].ToString());
                    dschitiet.Add(ct);
                }
                return true;
            }
            return false;
        }
        public static bool CapNhatChiTietChuyenBay(DTO.ChiTietChuyenBay ctcb)
        {
            try
            {
                
                string sql1 = "UPDATE ChiTietMayBay SET SanBayTrungGian =" + ctcb.SanBayTrungGian.ToString() + ", ThoiGianDung = '" + ctcb.ThoiGianDung.ToShortTimeString() + "'WHERE MaChuyenBay = '" + ctcb.MaChuyenBay.ToString() + "'";
                Config.AccessHelper.ExecuteNonQuery(sql1);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool ThemChuyenBay(DTO.ChiTietChuyenBay ctcb)
        {
            try
            {
                string sql = "insert into ChiTietMayBay(MaChuyenBay,SanBayTrungGian,ThoiGianDung) values ('";
                sql += ctcb.MaChuyenBay + "','";
                sql += ctcb.SanBayTrungGian + "','";
                sql += ctcb.ThoiGianDung + "')";
                Config.AccessHelper.ExecuteQuery(sql);
                return true;
            }  
              
            catch
            {
                return false;
            }
            
        }
    }
}
